package com.huayue.dao;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.huayue.entity.DepotInOrderDetails;
import com.huayue.util.PageHelper;
import com.mysql.DBHelper;

/**
 * 入库详情
 */
@Component
public class DepotInOrderDetailsDao implements BaseDao<DepotInOrderDetails> {
    /**
     * 添加方法
     *
     * @param entity
     * @return
     */
    @Override
    public int insert(DepotInOrderDetails entity) {
        return DBHelper.executeUpdate(
            "insert into depot_in_order_details (depot_in_order_id, product_id, number, remark, is_status) values ((select MAX(id) from depot_in_order),?,?,?,0);",
            entity.getProductId(), entity.getNumber(), entity.getRemark());
    }

    /**
     * 修改方法
     *
     * @param entity
     * @return
     */
    @Override
    public int update(DepotInOrderDetails entity) {
        return 0;
    }

    /**
     * 删除方法
     *
     * @param entity
     * @return
     */
    @Override
    public int delete(DepotInOrderDetails entity) {
        return 0;
    }

    /**
     * 查询方法 传入可变参数
     *
     * @param obj
     * @return
     */
    @Override
    public List<Map<String, Object>> findAll(Object... obj) {
        return null;
    }

    /**
     * 分页查询方法 传入分页对象和可变参数 分页对象用于分页查询 可变参数用于增加条件
     *
     * @param page
     * @param obj
     * @return
     */
    @Override
    public List<Map<String, Object>> findPage(PageHelper page, Object... obj) {
        return null;
    }

    /**
     * 查询一条数据 通常对象中只需存有id
     *
     * @param entity
     * @return
     */
    @Override
    public Map<String, Object> findOne(DepotInOrderDetails entity) {
        return null;
    }

    /**
     * 查询总条数 传入可变参数，用于增加条件
     *
     * @param obj
     * @return
     */
    @Override
    public int count(Object... obj) {
        return 0;
    }

    public List<Map<String, Object>> findDetailsByNowPurchaseOrder() {
        return DBHelper.executeQuery("select diod.product_id,sum(number) sumnumber from depot_in_order_details diod "
            + "left join depot_in_order dio on dio.id=diod.depot_in_order_id "
            + "left join purchase_order po on dio.purchase_order_id=po.id where po.id=(select max(purchase_order_id) from depot_in_order) GROUP BY product_id");
    }
}
